// 开始封装接口
import http from './http.js'
import md5 from "js-md5"
// 注册接口  在组件中调用接口就是调用方法
export function register(name, pwd) {
    return http.post('/user/register', {
        loginName: name,
        password: pwd
    })
}


// 登录接口
export function login(name, pwd) {
    return http.post('/user/login', {
        loginName: name,
        passwordMd5: md5(pwd)
    })
}

// 首页数据
export function getIndexInfo() {
    return http.get('/index-infos')
}
// 详情页
export function getInfoData(id) {
    return http.get('/goods/detail/' + id)
}
// 购物车接口
export function addCart(options) {
    return http.post('/shop-cart', options)
}

// 购物车接口
export function getCartList() {
    return http.get('/shop-cart')
}
// 购物车步进器接口
export function putCartList(id, count) {
    return http.put("/shop-cart", {
        cartItemId: id,
        goodsCount: count
    })
}
//购物车删除接口
export function deleteCartList(id) {
    return http.delete('/shop-cart/' + id)
}
// 地址列表接口
export function addressList() {
    return http.get('/address')
}
//添加商品地址接口
export function addressAdd(obj) {
    return http.post('/address', obj)
}
// 跟据商品id获取地址
export function getAddressId(id) {
    return http.get('/address/' + id)
}
// 地址编辑
export function editAddress(obj) {
    return http.put('/address', obj)
}
// 删除地址
export function removeAddress(id) {
    return http.delete('/address/' + id)
}
// 获取生成订单的商品
export function getOrder(id) {
    return http.get('/shop-cart/settle?cartItemIds=' + id)
}

// 生成订单接口
export function addOrder(addressId, cartItemIds) {
    return http.post('/saveOrder', { addressId, cartItemIds })
}


// 生成订单接口
export function paySuccess(orderNo, payType) {
    return http.get('/paySuccess', {
        params: {
            orderNo,
            payType
        }
    })
}

// 生成我的订单接口
export function getOrderList(pageNumber, status) {
    return http.get('/order', {
        params: {
            pageNumber,
            status
        }
    })
}
// 获取用户页面
export function getInfo() {
    return http.get('/user/info')
}